<%@ page language="java"  pageEncoding="utf-8"%>
<%@ page import="java.util.Vector,com.ejoysoft.wlanyz.business.Disturb,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException" %>
<%@ include file="../include/jsp/head.jsp"%>
<%
if(!globa.userSession.hasRight("20020"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
%>
<%
    //初始化
    Disturb  ap0=null;
    Disturb obj=new Disturb(globa);
    //查询条件
    String  strCity = ParamUtil.getString(request,"city","");
    String  strCountry = ParamUtil.getString(request,"country","");	
    String  strStartTime = ParamUtil.getString(request,"strStartTime","");
    String  strEndTime = ParamUtil.getString(request,"strEndTime","");
    String exportFlag = ParamUtil.getString(request,"exportFlag","");
	String exportContent = ParamUtil.getString(request,"exportContent","");
	String  strHotSpot = ParamUtil.getString(request,"classone","");
	String  strHotSpotTwo = ParamUtil.getString(request,"classtwo","");
	
		//当前页
		System.out.println("111111111111"+strHotSpotTwo);
    int intCurPage = ParamUtil.getInt(request,"strCurPage");
	String tWhere=" WHERE 1=1";
 
     if(!strCity.equals("")){
     tWhere += " and a.strCity LIKE '%"+ strCity +"%'";
    }
    if(!strCountry.equals("")){
     tWhere += " and a.strCountry LIKE '%"+ strCountry +"%'";     
    }

	//记录总数
	int intAllCount = 0;	
	if(exportFlag.equals("disturb_list")){
	 intAllCount = obj.getCount1(tWhere);
	}
	if(exportFlag.equals("disturb_country")){
	 intAllCount = obj.getCount11(tWhere);
	}
	else if(exportFlag.equals("disturb_classoneac")){
	 intAllCount = obj.getCount(tWhere);
	}
	else if(exportFlag.equals("disturb_classtwoac")){
	 tWhere += " and a.classoneac ='" + strHotSpot + "' ";
	 intAllCount = obj.getCount2(tWhere);
	}
	else if(exportFlag.equals("disturb_AP")){
	System.out.println("111111111111"+strHotSpotTwo);
	 tWhere += " and a.classoneac ='" + strHotSpot + "' and a.classtwoac ='" + strHotSpotTwo + "'";
	 System.out.println("111111111111"+tWhere);
	 intAllCount = obj.getCount3(tWhere);
	}
	//每页记录数
    String strPageSize = ParamUtil.getString(request,"strPageSize","10");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	
	StringBuffer sb = new StringBuffer();
	String strFileName = "";
	//System.out.println("================================"+exportFlag);
	if(exportFlag.equals("disturb_list"))
	{
	    Vector<Disturb> vctObj=obj.list1(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list1(tWhere,0,0,strStartTime,strEndTime);
		}
   	  
	    sb.append("城市,区县 数量,一级热点数量,ap数量,被干扰的AP数,信道质量\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getCity() + ",";
		       strSb += vctObj.get(i).getcountryNum()+ ",";
		       strSb += vctObj.get(i).gethotSpotNum() + "," ;
		       strSb += vctObj.get(i).getApNum() + "," ;
		       strSb += vctObj.get(i).getApDisturbNum() + "," ;
		       strSb += vctObj.get(i).getApQuality() + ",\n";
			   sb.append(strSb);
		    }
	    }
	     strFileName = strCity+"综合干扰分析表.csv";//自定义csv文件的文件
	} 
	if(exportFlag.equals("disturb_country"))
	{
	    Vector<Disturb> vctObj=obj.list11(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list11(tWhere,0,0,strStartTime,strEndTime);
		}
   	  
	    sb.append("城市,区县,一级热点数量,ap数量,被干扰的AP数,信道质量\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getCity() + ",";
		       strSb += vctObj.get(i).getCounty()+ ",";
		       strSb += vctObj.get(i).gethotSpotNum() + "," ;
		       strSb += vctObj.get(i).getApNum() + "," ;
		       strSb += vctObj.get(i).getApDisturbNum() + "," ;
		       strSb += vctObj.get(i).getApQuality() + ",\n";
			   sb.append(strSb);
		    }
	    }
	     strFileName = strCity+strCountry+"的综合干扰分析表.csv";//自定义csv文件的文件
	} 
	else if(exportFlag.equals("disturb_classoneac"))
	{
	    if(!strHotSpot.equals("")){
           tWhere += " and classoneac  LIKE '%"+ strHotSpot +"%'";     
        }
	    Vector<Disturb> vctObj=obj.list(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0,strStartTime,strEndTime);
		}
   	  
	    sb.append("城市,区县 ,一级热点,二级热点数量,ap数量,热点类型,被干扰的AP数,信道质量\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getCity() + ",";
		       strSb += vctObj.get(i).getCounty()+ ",";
		       strSb += vctObj.get(i).getHotSpot() + "," ;
		       strSb += vctObj.get(i).gethotSpotNum() + "," ;
		       strSb += vctObj.get(i).getApNum() + "," ;
		       strSb += vctObj.get(i).getAcType() + "," ;
		       strSb += vctObj.get(i).getApDisturbNum() + "," ;
		       strSb += vctObj.get(i).getApQuality() + ",\n";
			   sb.append(strSb);
		    }
	    }
	     strFileName = strCity+strCountry+"一级热点"+strHotSpot+"综合干扰分析表.csv";//自定义csv文件的文件
	} 
	
	else if(exportFlag.equals("disturb_classtwoac"))
	{
	    if(!strHotSpotTwo.equals("")) tWhere += " and a.classtwoac ='" + strHotSpotTwo + "' ";
	    Vector<Disturb> vctObj=obj.list2(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list2(tWhere,0,0,strStartTime,strEndTime);
		}
   	  
	    sb.append("城市,区县 ,二级热点,ap数量,热点类型,被干扰的AP数,信道质量\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String strSb = vctObj.get(i).getCity() + ",";
		       strSb += vctObj.get(i).getCounty()+ ",";
		       strSb += vctObj.get(i).getHotSpot() + "," ;
		       strSb += vctObj.get(i).getApNum() + "," ;
		       strSb += vctObj.get(i).getAcType() + "," ;
		       strSb += vctObj.get(i).getApDisturbNum() + "," ;
		       strSb += vctObj.get(i).getApQuality() + ",\n";
			   sb.append(strSb);
		    }
	    }
	     strFileName = strCity+strCountry+"一级热点"+strHotSpot+"的二级热点"+strHotSpotTwo+"综合干扰分析表.csv";//自定义csv文件的文件
	}
	
	else if(exportFlag.equals("disturb_AP"))
	{
	    Vector<Disturb> vctObj=obj.list3(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list3(tWhere,0,0,strStartTime,strEndTime);
		}
   	  
	    sb.append("城市,区县 ,二级热点,ap名称,是否被干扰,信道质量\n");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       String yesOrNo = "否";
		       String strSb = vctObj.get(i).getCity() + ",";
		       strSb += vctObj.get(i).getCounty()+ ",";
		       strSb += vctObj.get(i).getHotSpot() + "," ;
		       strSb += vctObj.get(i).getApName() + "," ;
		       if(vctObj.get(i).getApQuality() > 10) yesOrNo = "是";
		       strSb += yesOrNo + "," ;
		       strSb += vctObj.get(i).getApQuality() + ",\n";
			   sb.append(strSb);
		    }
	    }
	     strFileName = strCity+strCountry+"一级热点"+strHotSpot+"的二级热点"+strHotSpotTwo+"AP综合干扰分析表.csv";//自定义csv文件的文件
	}
	System.out.println("================================"+strFileName);
	///strFileName="ffffffffffffffffff";
	if(!exportFlag.equals(null)){
			response.setContentType("APPLICATION/*");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    output.write(sb.toString().getBytes());
	}

	
%>
<%@ include file="../include/jsp/footer.jsp"%>
